#include <ansi_c.h>
#include <cvirte.h>		
#include <userint.h>
#include "myrand.h"

static int panelHandle;

int main(int argc, char *argv[]) {
	if (InitCVIRTE(0, argv, 0) == 0)
		return -1; /* out of memory */
	if ((panelHandle = LoadPanel(0, "myrand.uir", PANEL)) < 0)
		return -1;
	DisplayPanel(panelHandle);
	RunUserInterface();
	DiscardPanel(panelHandle);
	return 0;
}

int CVICALLBACK Startcallback (int panel,int control,int event, void *callbackData, int eventData1, int eventData2) {
	int i;
	double n;
	double x,a[1000];
	switch (event) {
		case EVENT_COMMIT:
		DeleteGraphPlot (panelHandle, PANEL_GRAPH, -1, VAL_IMMEDIATE_DRAW);
		GetCtrlVal (panelHandle, PANEL_max, &n);
		for(i=0;i<1000;i++) {
			x=n*rand()/32767;
			a[i]=x;
		}

		PlotWaveform (panelHandle, PANEL_GRAPH, a, 1000, VAL_DOUBLE, 1.0, 0.0, 0.0, 1.0, VAL_THIN_LINE, VAL_EMPTY_SQUARE, VAL_SOLID, 1, VAL_RED);

		break;
	}
	return 0;
}

int CVICALLBACK Closecallback (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) {
	switch (event) {
		case EVENT_COMMIT:
		QuitUserInterface (0);
		break;
	}
	return 0;
}

int CVICALLBACK Clearcallback (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) {
	switch (event) {
		case EVENT_COMMIT:
		DeleteGraphPlot (panelHandle, PANEL_GRAPH, -1, VAL_IMMEDIATE_DRAW);
		break;
	}
	return 0;
}
